<template>
  <a-modal
    :title="'列表'"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :destroyOnClose="true"
    @ok="handleSubmit"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">

        <a-table
                row-key="index"
                size="small"
                :columns="columns"
                :dataSource="datalist"
        >
                <span slot="range" slot-scope="text, record">

                </span>
        </a-table>
    </a-spin>
      <template slot="footer">
          <a-button @click="handleDelete" type="primary" :loading="confirmLoading">删除</a-button>
          <a-button @click="handleCancel" style="margin-right: .8rem">关闭</a-button>
      </template>
  </a-modal>
</template>

<script>
  import { getAction, postAction,deleteAction } from '@/api/manage'
  export default {
    name: 'EyeErrortxtShow',
    components: {
    },
    data () {
      return {
        visible: false,
        confirmLoading: false,
        formInfo: {
          name: undefined,
          classname: undefined,
          schname: undefined,
          gradename: undefined,
          identity: undefined,
          parentid: undefined,
          contact: undefined,
          errortext: undefined,
          createTime: undefined,
          departCode: undefined,
          remark: undefined,
          projectDesc: undefined,
          wx: ''
        },
          // 表头
          // 如果需要字典，那么需要在columns列中加入 customRender: (text) => this.$sysDictFilter(text, 'xxxx')xxxx 为dataIndex
          columns: [
              {
                  title: '姓名',
                  dataIndex: 'name'
              },
              {
                  title: '学校',
                  dataIndex: 'schname'
              },
              {
                  title: '年级',
                  dataIndex: 'gradename'
              },
              {
                  title: '班级',
                  dataIndex: 'classname'
              },
              {
                  title: '失败原因',
                  dataIndex: 'errortext'
              },
              {
                  title: '操作时间',
                  dataIndex: 'createtime',
                  key: 'createtime',
                  customRender: (text) => this.$momentFormat(text, 'YYYY-MM-DD HH:mm:ss')
              }
          ],
          datalist:[],
        url: {
          saveInfo: '/system/eyeErrortxt/save',
          getInfo: '/system/eyeErrortxt/info',
            list: '/system/eyeErrortxt/list',
            delete: '/system/eyeErrortxt/delete'
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit()
      },
      edit () {
          postAction(this.url.list,{"pageSize":1000,"pageNo":1})
              .then(res => {
                  console.log(res)
                  this.datalist =  res.result.data.records
              })
        this.visible = true
      },
        handleClear(){

        },
      // 确定
      handleSubmit () {
        // 触发表单验证
        this.confirmLoading = true
        this.$refs.ruleForm.validate(valid => {
          console.log(valid)
          if (valid) {
            postAction(this.url.saveInfo, this.formInfo).then(res => {
              this.$message.success(res.content)
              this.$emit('ok', this.formInfo)
              this.close()
            }).finally(() => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
        handleDelete(){
            deleteAction(this.url.delete, {ids:'' }).then((resp) => {
                this.$message.success('删除成功!')
                this.$refs.table.refresh(true)
            })
        },
      // 关闭
      handleCancel () {
        this.close()
      },
      close () {
        // this.$refs.ruleForm.resetFields()
        this.$objToReset(this.formInfo)
        this.$emit('close')
        this.visible = false
      },
      editorOk (val) {
        this.formInfo.content = val
      }
    }
  }
</script>
